package org.goyo.main.domain.entity.sale;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.goyo.main.domain.entity.BaseObject;
import org.goyo.main.domain.entity.base.MainResponsibleTransportCo;
import org.goyo.main.domain.entity.base.TransportMode;
/**
 * 发运单
 * 
 * @author chenchuan
 * 2014年11月12日
 */
@Entity
public class Dispatch  extends BaseObject implements Serializable {

	private static final long serialVersionUID = 1L;
	//单据编号前缀
	public static final String BIZTYPE = "FY";
	/**
	 * 发运类型	
	 */
	@Column
	private String dispatchType;
	/**
	 * 发运总路线	
	 */
	@Column
	private String dispatchBus;
	/**
	 * 主承运方	
	 */
	@ManyToOne
	@JoinColumn(name="shipperId")
	private MainResponsibleTransportCo shipper;
	/**
	 * 车辆	
	 */
	@Column
	private String car;
	/**
	 * 司机	
	 */
	@Column
	private String driver;
	/**
	 * 运输方式	
	 */
	@ManyToOne
	@JoinColumn(name="transportModeId")
	private TransportMode transitWay;
	/**
	 * 费用金额	
	 */
	@Column
	private BigDecimal taxAmount = BigDecimal.ZERO;
	
	@OneToMany(fetch = FetchType.LAZY,cascade={CascadeType.ALL},mappedBy="dispatch")
	private List<DispatchEntry> entrys = new ArrayList<DispatchEntry>();
	
	public String getDispatchType() {
		return dispatchType;
	}
	public void setDispatchType(String dispatchType) {
		this.dispatchType = dispatchType;
	}
	public String getDispatchBus() {
		return dispatchBus;
	}
	public void setDispatchBus(String dispatchBus) {
		this.dispatchBus = dispatchBus;
	}
	public List<DispatchEntry> getEntrys() {
		return entrys;
	}
	public void setEntrys(List<DispatchEntry> entrys) {
		if(entrys != null){
			for(DispatchEntry entry : entrys){
				entry.setDispatch(this);
			}
		}
		this.entrys = entrys;
	}
	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public String getCar() {
		return car;
	}
	public void setCar(String car) {
		this.car = car;
	}
	public String getDriver() {
		return driver;
	}
	public void setDriver(String driver) {
		this.driver = driver;
	}
	public MainResponsibleTransportCo getShipper() {
		return shipper;
	}
	public void setShipper(MainResponsibleTransportCo shipper) {
		if(shipper != null &&("".equals(shipper.getUuid()) || shipper.getUuid()==null))
			this.shipper = null;
		else
			this.shipper = shipper;		
	}
	public TransportMode getTransitWay() {
		return transitWay;
	}
	public void setTransitWay(TransportMode transitWay) {
		if(transitWay != null &&("".equals(transitWay.getUuid()) || transitWay.getUuid()==null))
			this.transitWay = null;
		else
			this.transitWay = transitWay;	
	}
	public BigDecimal getTaxAmount() {
		return taxAmount;
	}
	public void setTaxAmount(BigDecimal taxAmount) {
		this.taxAmount = taxAmount;
	}
	
}
